package com.sxj.corejava.code09_集合.Map;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 * @author 石小俊
 * 2024年07月25日 13:32
 */
public class Test04_Hashtable {
    public static void main(String[] args) {
        Hashtable<Integer, String> map = new Hashtable<>();
        map.put(1, "admin");
        map.put(1, "alice");
        map.put(2, "alice");
        // key与value均不能为null
        //map.put(null,"admin");
        //map.put(3,null);
        System.out.println(map);

        System.out.println("********************遍历方式一********************");
        Enumeration<Integer> keys = map.keys();
        while (keys.hasMoreElements()) {
            Integer key = keys.nextElement();
            String value = map.get(key);
            System.out.println("key:" + key + ",value:" + value);
        }

        System.out.println("********************遍历方式二********************");
        Enumeration<String> values = map.elements();
        while (values.hasMoreElements()) {
            String value = values.nextElement();
            System.out.println("value:" + value);
        }
    }
}
